package com.xunk.equipment.controller;

import com.xunk.common.core.web.domain.AjaxResult;
import com.xunk.equipment.service.dnake.service.DnakeSceneService;
import com.xunk.equipment.service.dnake.service.DnakeService;
import com.xunk.equipment.service.dnake.vo.DnakeLinkageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.equipment.controller
 * @ClassName: DnakeController
 * @Author: wangtong
 * @Description: 狄耐克接口
 * @Date: 2021/6/7 16:19
 * @Version: 1.0
 */
@RestController
@RequestMapping(value = "/dnake")
public class DnakeController extends BaseController {
    @Resource
    private DnakeSceneService dnakeSceneService;

    @Resource
    private DnakeService dnakeService;

    /**
     * 调用场景
     *
     * @param gatewayDeviceSn 网关sn号
     * @param sceneNo         场景号
     */
    @GetMapping("scene/{gatewayDeviceSn}/{sceneNo}")
    public AjaxResult ctrlScene(@PathVariable String gatewayDeviceSn, @PathVariable Integer sceneNo) {
        dnakeSceneService.ctrlScene(gatewayDeviceSn, sceneNo);
        return AjaxResult.success();
    }

    /**
     * 设置场景
     *
     * @param gatewayDeviceSn 网关sn号
     * @param sceneNo         场景号
     * @param dataList        联动关系
     */
    @PostMapping("scene/{gatewayDeviceSn}/{sceneNo}")
    public AjaxResult setScene(@PathVariable String gatewayDeviceSn, @PathVariable Integer sceneNo, @RequestBody List<DnakeLinkageData> dataList) {
        dnakeSceneService.setScene(gatewayDeviceSn, sceneNo, dataList);
        return AjaxResult.success();
    }

    /**
     * 删除场景
     *
     * @param gatewayDeviceSn 网关sn号
     * @param sceneNo         场景号
     */
    @DeleteMapping("scene/{gatewayDeviceSn}/{sceneNo}")
    public AjaxResult delScene(@PathVariable String gatewayDeviceSn, @PathVariable Integer sceneNo) {
        dnakeSceneService.delScene(gatewayDeviceSn, sceneNo);
        return AjaxResult.success();
    }

    /**
     * 删除全部场景
     *
     * @param gatewayDeviceSn 网关sn号
     */
    @DeleteMapping("scene/dellAll/{gatewayDeviceSn}")
    public AjaxResult delAllScene(@PathVariable String gatewayDeviceSn) {
        dnakeSceneService.delAllScene(gatewayDeviceSn);
        return AjaxResult.success();
    }

    /**
     * 根据网关sn号获取对应对码绑定信息
     *
     * @param gatewayDeviceSn 网关sn号
     */
    @GetMapping("codeBindingInfo/{gatewayDeviceSn}")
    public AjaxResult getCodeBindingInfo(@PathVariable String gatewayDeviceSn) {
        return dnakeService.getCodeBindingInfo(gatewayDeviceSn);
    }

    /**
     * 网关上线后，app或者web调用此接口获取网关子设备
     *
     * @param gatewayDeviceSn 网关sn号
     */
    @GetMapping("subset/{gatewayDeviceSn}")
    public AjaxResult getSubset(@PathVariable String gatewayDeviceSn) {
        return dnakeService.getSubset(gatewayDeviceSn);
    }
}
